package day20171113;

import java.io.*;

public class TestFile {

    private static Object F;

    public static void main(String[] args) {
        File myFile = new File("F:\\Test.txt");
        try {
            myFile.createNewFile();
            System.out.println("创建文件成功.");
        } catch (IOException e) {
            System.out.println("载入文件出错。");         //运用file类创建一个txt文件
        }

        //运用Bufferedwriter向创建的文件写入一些内容
        try {
            BufferedWriter writer = new BufferedWriter(new FileWriter("F:\\Test.txt"));
            writer.write("zhuxuiafkadjfkadsfjdskfjakdsfjkd jkj jkjfksakfkasdjf");
            writer.newLine();
            writer.write("打飞机澳康达设计费快递费");
            writer.close();
            System.out.println("文件写入内容成功.");
        } catch (IOException e) {
            e.printStackTrace();
        }

        try {
            BufferedReader reader = new BufferedReader(new FileReader("F:\\Test.txt"));
            while (true) {
                String s = reader.readLine();
                if (s == null) {
                    break;
                } else {
                    System.out.println(s);
                }
            }
            reader.close();

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
